<template>
  <div class="main-bar" ref="barRef"></div>
</template>

<script lang="ts">
export default {
  name: "barChart",
};
</script>

<script lang="ts" setup>
import * as echarts from "echarts";
import { watch, ref } from "vue";
const barRef = ref();
const props = defineProps<{
  orderUserTrendAxis: string[];
  orderUserTrend: number[];
}>();
watch(
  () => props.orderUserTrend,
  () => {
    const myChart = echarts.init(barRef.value);
    myChart.setOption({
      xAxis: {
        data: props.orderUserTrendAxis,
      },
      yAxis: {
        show: false,
      },
      grid: {
        top: 0,
        bottom: 0,
        left: -5,
        right: -5,
      },
      tooltip: {
        trigger: "axis",
      },
      series: {
        name: "今日交易数",
        type: "bar",
        data: props.orderUserTrend,
        itemStyle: {
          color: "#3398db",
        },
        barWidth: 10,
      },
    });
  }
);
</script>

<style scoped>
.main-bar {
  width: 100%;
  height: 100%;
}
</style>
